package com.future.heatwave.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.future.heatwave.db.entity.AchieveDataBean
import com.future.heatwave.db.entity.FreeSectionsRecord
import com.future.heatwave.db.entity.GainMetadataBean
import com.future.heatwave.db.entity.ObtainRecordsBean
import com.future.heatwave.db.entity.ParticDatumBean
import com.future.heatwave.db.entity.SectionsEntityRecord

@Database(
    entities = [AchieveDataBean::class, GainMetadataBean::class, ObtainRecordsBean::class,
        FreeSectionsRecord::class, SectionsEntityRecord::class,
        ParticDatumBean::class],
    version = 9,
    exportSchema = false
)
@TypeConverters(ListStringConverter::class)
abstract class VideoDatabase : RoomDatabase() {
    abstract fun videoDao(): ItemDo

    companion object {
        @Volatile
        private var INSTANCE: VideoDatabase? = null
        fun getDb(context: Context): VideoDatabase {
            val tempInstance = INSTANCE
            if (tempInstance != null) {
                return tempInstance
            }
            synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    VideoDatabase::class.java,
                    "heat_short.db"
                )
                    .fallbackToDestructiveMigration()
                    .allowMainThreadQueries()
                    .build()
                INSTANCE = instance
            }
            return INSTANCE!!
        }
    }
}